package safeCommitter.core.view.main;

import java.net.MalformedURLException;
import java.net.URL;

import org.eclipse.jdt.internal.ui.viewsupport.ImageImageDescriptor;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;

import safeCommitter.core.template.Activator;

public class SCViewUtils {

	@SuppressWarnings("deprecation")
	public static Image createImage(final String path) {
		URL url = Activator.getDefault().getDescriptor().getInstallURL();
		ImageDescriptor descriptor = null;
		try {
			descriptor = ImageDescriptor.createFromURL(new URL(url, path));
		} catch (MalformedURLException e) {
			descriptor = ImageDescriptor.getMissingImageDescriptor();
		}
		return descriptor.createImage();
	}

	public static ImageDescriptor getImageDescriptor(final String path) {
		return new ImageImageDescriptor(createImage(path));
	}

	public static Image getImage2(final String path) {
		return Activator.getImageDescriptor(path).createImage();
	}

}
